package cn.com.jtang.wedding.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.dao.AdminUserDao;
import cn.com.jtang.wedding.model.AdminUser;

public class AdminUserDaoImpl extends BaseDaoImpl implements AdminUserDao {
	private static final String ID = "id";
	private static final String ADMINUSERNAME = "adminUserName";
	private static final String PASSWORD = "password";
	private static final String COMPANYNAME = "companyName";
	private static final String TELEPHONE = "telephone";
	private static final String CONTACT = "contact";
	private static final String MOBILE = "mobile";
	private static final String PROVINCE = "province";
	private static final String CITY = "city";
	private static final String ADDRESS = "address";
	private static final String COMPANYTYPE = "companyType";
	private static final String REGISTTIME = "registTime";
	private static final String PARENTID = "parentId";
	private static final String STATE = "state";
	private static final String DESCRIPTION = "description";
	private static final String TIMES = "times";
	private static final String ADMINTYPE = "adminType";


	@Override
	public List insertModelToList(Object object) {
		AdminUser adminUser = (AdminUser)object;
		List args = new ArrayList();
		args.add(0);
		args.add(adminUser.getAdminUserName());	
		args.add(adminUser.getPassword());
		args.add(adminUser.getCompanyName());
		args.add(adminUser.getTelephone());
		args.add(adminUser.getContact());
		args.add(adminUser.getMobile());
		args.add(adminUser.getProvince());
		args.add(adminUser.getCity());
		args.add(adminUser.getAddress());
		args.add(adminUser.getCompanyType());
		args.add(adminUser.getRegistTime());
		args.add(adminUser.getParentId());
		args.add(adminUser.getState());
		args.add(adminUser.getDescription());
		args.add(adminUser.getTimes());
		args.add(adminUser.getAdminType());
		return args;
	}

	@Override
	public Object resultMapper(ResultSet rs, int rowNum) throws SQLException {
		AdminUser adminUser = new AdminUser();
		adminUser.setId(rs.getLong(ID));
		adminUser.setAdminUserName(rs.getString(ADMINUSERNAME));
		adminUser.setPassword(rs.getString(PASSWORD));
		adminUser.setCompanyName(rs.getString(COMPANYNAME));
		adminUser.setTelephone(rs.getString(TELEPHONE));
		adminUser.setContact(rs.getString(CONTACT));
		adminUser.setMobile(rs.getString(MOBILE));
		adminUser.setProvince(rs.getString(PROVINCE));
		adminUser.setCity(rs.getString(CITY));
		adminUser.setAddress(rs.getString(ADDRESS));
		adminUser.setCompanyType(rs.getString(COMPANYTYPE));
		adminUser.setRegistTime(rs.getDate(REGISTTIME));
		adminUser.setParentId(rs.getLong(PARENTID));
		adminUser.setState(rs.getLong(STATE));
		adminUser.setDescription(rs.getString(DESCRIPTION));
		adminUser.setTimes(rs.getLong(TIMES));
		adminUser.setAdminType(rs.getLong(ADMINTYPE));	
		return adminUser;
	}

	@Override
	public Map updateModelToMap(Object object) {
		AdminUser adminUser = (AdminUser)object;
		Map map = new HashMap();
		map.put(ID, adminUser.getId());
		map.put(ADMINUSERNAME, adminUser.getAdminUserName());
		map.put(PASSWORD, adminUser.getPassword());
		map.put(COMPANYNAME, adminUser.getCompanyName());
		map.put(TELEPHONE, adminUser.getTelephone());
		map.put(CONTACT, adminUser.getContact());
		map.put(MOBILE, adminUser.getMobile());
		map.put(PROVINCE, adminUser.getProvince());
		map.put(CITY, adminUser.getCity());
		map.put(ADDRESS, adminUser.getAddress());
		map.put(COMPANYTYPE, adminUser.getCompanyType());
		map.put(REGISTTIME, adminUser.getRegistTime());
		map.put(PARENTID, adminUser.getParentId());
		map.put(STATE, adminUser.getState());
		map.put(DESCRIPTION, adminUser.getDescription());
		map.put(TIMES, adminUser.getTimes());
		map.put(ADMINTYPE, adminUser.getAdminType());
		return map;
	}
	
	public String insert(AdminUser adminUser){
		return super.insert(adminUser);
	}
	
	public AdminUser queryById(Long id){
		return (AdminUser)super.queryById(id);
	}
	
	public int updateById(Long id, AdminUser adminUser) {
		return super.updateById(id, adminUser);
	}
	
	public int deleteById(Long id) {
		return super.deleteById(id);
	}
	
	public List queryAll(Map<String, Object> map, int start,int end, String... orderByStr){
		return super.queryAll(map, start, end, orderByStr);
	}
	
	public AdminUser queryByKey(String keyName, String keyValue){
		return (AdminUser)jdbcDao.queryByKey(this.tableName,keyName, keyValue, new ObjectMapper());
	}



}
